package test.marui.com.mytest;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

import test.marui.com.mytest.ui.video.VideoActivity;
import test.marui.com.mytest.ui.cntenSDKDemo.CntenSDKDemoActivity;
import test.marui.com.mytest.ui.viewPagerTest.ViewPagerTestActivity;
import test.marui.com.mytest.view.bDLocation.BDLocationActivity;
import test.marui.com.mytest.view.bluetooth.BluetoothActivity;
import test.marui.com.mytest.view.layerView.LayerActivity;
import test.marui.com.mytest.view.notification.NotificationActivity;
import test.marui.com.mytest.view.photoOperation.PhotoOperationActivity;
import test.marui.com.mytest.view.slideBackView.SlideBackViewActivity;
import test.marui.com.mytest.view.verifyEditView.VerifyEditExampleActivity;


public class MainActivity extends AppCompatActivity {

    public ArrayList<String> exampleList = new ArrayList<>();
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;

        RecyclerView rv = findViewById(R.id.rv);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        rv.setLayoutManager(manager);
        MyAdapter adapter = new MyAdapter(this, exampleList);
        adapter.setOnItemClickListener(new MyOnItemClickListener());
        rv.setAdapter(adapter);

        exampleList.add("验证码输入框");
        exampleList.add("自定义弹出框");
        exampleList.add("仿即刻滑动返回");
        exampleList.add("ViewPager+TabLayout复习");
        exampleList.add("测试北斗定位");
        exampleList.add("蓝牙的使用");
        exampleList.add("北斗SDK对接");
        exampleList.add("图片存取");
        exampleList.add("android9通知");
        exampleList.add("视频");
        adapter.notifyDataSetChanged();

    }

    private class MyOnItemClickListener implements MyAdapter.OnItemClickListener {
        @Override
        public void onClick(int position) {
            switch (position) {
                case 0:
                    Intent intent = new Intent(context, VerifyEditExampleActivity.class);
                    startActivity(intent);
                    break;
                case 1:
                    Intent intent1 = new Intent(context, LayerActivity.class);
                    intent1.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent1);
                    break;
                case 2:
                    Intent intent2 = new Intent(context, SlideBackViewActivity.class);
                    intent2.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent2);
                    overridePendingTransition(R.anim.fade_right_in, R.anim.fade_left_out);
                    break;
                case 3:
                    Intent intent3 = new Intent(context, ViewPagerTestActivity.class);
                    intent3.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent3);
                    overridePendingTransition(R.anim.fade_right_in, R.anim.fade_left_out);
                    break;
                case 4:
                    Intent intent4 = new Intent(context, BDLocationActivity.class);
                    intent4.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent4);
                    overridePendingTransition(R.anim.fade_right_in, R.anim.fade_left_out);
                    break;
                case 5:
                    Intent intent5 = new Intent(context, BluetoothActivity.class);
                    intent5.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent5);
                    overridePendingTransition(R.anim.fade_right_in, R.anim.fade_left_out);
                    break;
                case 6:
                    Intent intent6 = new Intent(context, CntenSDKDemoActivity.class);
                    intent6.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent6);
                    overridePendingTransition(R.anim.fade_right_in, R.anim.fade_left_out);
                    break;
                case 7:
                    Intent intent7 = new Intent(context, PhotoOperationActivity.class);
                    intent7.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent7);
                    overridePendingTransition(R.anim.fade_right_in, R.anim.fade_left_out);
                    break;
                case 8:
                    Intent intent8 = new Intent(context, NotificationActivity.class);
                    intent8.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent8);
                    overridePendingTransition(R.anim.fade_right_in, R.anim.fade_left_out);
                    break;
                case 9:
                    Intent intent9 = new Intent(context, VideoActivity.class);
                    intent9.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(intent9);
                    overridePendingTransition(R.anim.fade_right_in, R.anim.fade_left_out);
                    break;

            }
        }
    }

    static class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

        private Context context;
        private ArrayList<String> list;
        private OnItemClickListener mOnItemClickListener;

        MyAdapter(Context context, ArrayList<String> list) {
            this.context = context;
            this.list = list;
        }

        class ViewHolder extends RecyclerView.ViewHolder {
            TextView title;

            ViewHolder(View v) {
                super(v);
                title = v.findViewById(R.id.textView);
            }
        }

        @NonNull
        @Override
        public MyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_main, parent, false);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull MyAdapter.ViewHolder holder, int position) {
            holder.title.setText(list.get(position));
            holder.title.setTag(position);
            holder.title.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = (int) v.getTag();
                    if (mOnItemClickListener != null) {
                        mOnItemClickListener.onClick(position);
                    }
                }
            });
        }

        @Override
        public int getItemCount() {
            if (list == null) {
                return 0;
            }
            return list.size();
        }

        interface OnItemClickListener {
            void onClick(int position);
        }

        public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
            this.mOnItemClickListener = mOnItemClickListener;
        }

    }

}
